import { useEffect } from "../vue/hooks";
import type { EventEmitter } from "./event-emitter.ts";

export function useMitt<Events extends Dict, K extends keyof Events>(emitter: EventEmitter<Events>, event: K, handler: (e: Events[K]) => any) {
  useEffect(() => {
    emitter.on(event, handler);

    return () => {
      emitter.off(event, handler);
    };
  });
}
